<?php 
$sql = "SELECT a.NILAI_ID, a.DETACHIEV_ID, b.ACHIEV_JENIS, b.ACHIEV_BIDANG, 
			c.DETACHIEV_TINGKAT, c.DETACHIEV_NAMA, d.REWARD_ID, d.REWARD_JENIS, d.REWARD_NAMA, 
			a.NILAI_POINT, a.NILAI_MIN, a.NILAI_MAX
		FROM nilai as a, 
		prestasipelanggaran as b, 
		detil_prestasi_pelanggaran as c, 
		rewarddanpunishment as d 
		WHERE a.DETACHIEV_ID = c.DETACHIEV_ID AND 
			b.ACHIEV_ID = c.ACHIEV_ID AND 
			a.REWARD_ID = d.REWARD_ID ";

if ($key){
	$sql .= " AND 
			(a.NILAI_ID LIKE '%$key%' OR
			 a.DETACHIEV_ID LIKE '%$key%' OR
			 b.ACHIEV_JENIS LIKE '%$key%' OR
			 b.ACHIEV_BIDANG LIKE '%$key%' OR
			 c.DETACHIEV_TINGKAT LIKE '%$key%' OR
			 c.DETACHIEV_NAMA LIKE '%$key%' OR
			 d.REWARD_ID LIKE '%$key%' OR
			 d.REWARD_JENIS LIKE '%$key%' OR
			 d.REWARD_NAMA LIKE '%$key%' OR
			 a.NILAI_POINT LIKE '%$key%' OR
			 a.NILAI_MIN LIKE '%$key%' OR
			 a.NILAI_MAX LIKE '%$key%') ";
}
if ($orderby){
	$sql .= " ORDER BY $orderby ";
}
?>

<?php $result = mysql_query($sql)?>
<?php while ($row = mysql_fetch_assoc($result)):?>
<tr <?php echo tag_zebra($z++)?>>
    <td align="center"><?php echo $row['NILAI_ID']?></td>
    <td><?php echo $row['ACHIEV_JENIS']?></td>
    <td><?php echo $row['ACHIEV_BIDANG']?></td>
    <td><?php echo $row['DETACHIEV_TINGKAT']?></td>
    <td><?php echo $row['DETACHIEV_NAMA']?></td>
    <td><?php echo $row['REWARD_JENIS']?></td>
    <td><?php echo $row['REWARD_NAMA']?></td>
    <td align="center"><?php echo $row['NILAI_POINT']?></td>
    <td align="center"><?php echo $row['NILAI_MIN']?></td>
    <td align="center"><?php echo $row['NILAI_MAX']?></td>
	<td align="right">
		<a onclick="doEdit('<?php echo $row['NILAI_ID']?>')">Edit</a><a class="marginL5"
		onclick="doDelete('<?php echo $row['NILAI_ID']?>')">Delete</a></td>
</tr>
<?php endwhile;?>